package pl.koszolko.documentclustering.cluster;

import java.util.Set;
import java.util.TreeSet;

import pl.koszolko.documentclustering.cluster.document.DocumentForClustering;

public class ClusterMinDistance implements Cluster {
	private static final long serialVersionUID = 1L;
	
	private Set<DocumentForClustering> documents;
	
	public ClusterMinDistance() {
		documents = new TreeSet<DocumentForClustering>();
	}
	
	@Override
	public void addDocument(DocumentForClustering doc) {
		documents.add(doc);
	}

	@Override
	public Double countDistance(Cluster cluster) {
		Double maxDistance = 0.0;
		Double tmpDistance = 0D;
		for(DocumentForClustering doc : documents) {
			for(DocumentForClustering doc2 : cluster.getDocuments()) {
				tmpDistance = doc.countSimilarity(doc2);
				if(tmpDistance >= maxDistance) {
					maxDistance = tmpDistance;
				}
			}
		}
		
		return maxDistance;
	}

	public Set<DocumentForClustering> getDocuments() {
		return documents;
	}

	public void setDocuments(Set<DocumentForClustering> documents) {
		this.documents = documents;
	}

	@Override
	public void addDocuments(Set<DocumentForClustering> documents) {
		for(DocumentForClustering doc : documents) {
			addDocument(doc);
		}
	}
	
	@Override
	public String toString() {
		String text = "Klaster zawiera:\n";
		for(DocumentForClustering d: documents) {
			text += d.getTitle() + "\n";
		}
		text += "##\n";
		return text;
	}

}
